﻿using System;
using System.Text;
using Xunit;

namespace Unity.String.Tests.Number
{
    public class HexConverterTest
    {
        [Fact]
        public void ToBytesBufferTest()
        {
            byte testByteValue = 7;
            Span<byte> testByteBuffer = new Span<byte>(new byte[2]);
            HexConverter.ToBytesBuffer(testByteValue, testByteBuffer);
            Assert.Equal("07", Encoding.ASCII.GetString(testByteBuffer.ToArray()));
        }

        [Fact]
        public void ToStringTest()
        {
            string testStringValue = "Test message";
            ReadOnlySpan<byte> testBytesToStringValue = 
                Encoding.ASCII.GetBytes(testStringValue).AsSpan();
            string returnToStringResult = HexConverter.ToString(testBytesToStringValue);
            string needHexReturnValue = "54657374206D657373616765";
            Assert.Equal(needHexReturnValue, returnToStringResult);
            
            string testBigStringValue = "Extra big text test message";
            ReadOnlySpan<byte> testBytesToBigStringValue = 
                Encoding.ASCII.GetBytes(testBigStringValue).AsSpan();
            string returnBigToStringResult = HexConverter.ToString(testBytesToBigStringValue);
            string needBigHexReturnValue = "45787472612062696720746578742074657374206D657373616765";
            Assert.Equal(needBigHexReturnValue, returnBigToStringResult);
        }
        
        [Fact]
        public void ToCharUpperTest()
        {
            int testZeroIntValue = 0;
            char returnZeroCharValue = HexConverter.ToCharUpper(testZeroIntValue);
            Assert.Equal('0', returnZeroCharValue);
            
            int testPositiveIntValue = 123;
            char returnPositiveCharValue = HexConverter.ToCharUpper(testPositiveIntValue);
            Assert.Equal('B', returnPositiveCharValue);
            
            int testNegativeIntValue = -123;
            char returnNegativeCharValue = HexConverter.ToCharUpper(testNegativeIntValue);
            Assert.Equal('5', returnNegativeCharValue);
        }

        [Fact]
        public void ToCharLowerTest()
        {
            int testZeroIntValue = 0;
            char returnZeroCharValue = HexConverter.ToCharLower(testZeroIntValue);
            Assert.Equal('0', returnZeroCharValue);
            
            int testPositiveIntValue = 123;
            char returnPositiveCharValue = HexConverter.ToCharLower(testPositiveIntValue);
            Assert.Equal('b', returnPositiveCharValue);
            
            int testNegativeIntValue = -123;
            char returnNegativeCharValue = HexConverter.ToCharLower(testNegativeIntValue);
            Assert.Equal('5', returnNegativeCharValue);
        }
        
    }
}